how to do encapsulation in javascript